package exercise.day10;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/11/13 14:52
 */
public class CM62_CheckWon {
    public boolean checkWon(int[][] board) {
// write code here
        int size = board.length;
        int sum = 0;
        int i = 0;
        int j = 0;
//检查每一行的个数是否为size
        for (i = 0; i < size; i++) {
            for (j = 0; j < size; j++) {
                sum += board[i][j];
            }
            if (sum == size) {
                return true;
            }
        }
//检查每一列的个数是否为size
        for (i = 0; i < size; i++) {
            sum = 0;
            for (j = 0; j < size; j++) {
                sum += board[j][i];
            }
            if (size == sum) {
                return true;
            }
        }
//检查主对角线的值
        sum = 0;
        for ( i = 0; i < size; i++) {
            sum += board[i][i];
        }
        if (size == sum) {
            return true;
        }
//检查副对角线的值
        sum = 0;
        for (i = 0; i < size; i++) {
            sum += board[i][size - i - 1];
        }
        if (size == sum) {
            return true;
        }
        return false;
    }
}
